package ch1.base;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * 只有一个main方法的程序启用了哪些线程
 */
public class OnlyMain {
    public static void main(String[] args) {
        //线程系统的管理接口
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        //获取线程和线程堆栈信息，不需要获取同步的monitor和synchronize信息
        ThreadInfo[] threadInfoArray = threadMXBean.dumpAllThreads(false, false);
        for (ThreadInfo threadInfo : threadInfoArray) {
            System.out.println(threadInfo.getThreadId() + "————" + threadInfo.getThreadName());
        }
    }
}